package com.taptech.doufu.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

import com.taptech.doufu.util.TTLog;

public class ResizeLayout extends RelativeLayout {
	private OnRelativeLayoutResizeListener listener;
	private int initHeight = 0;

	public ResizeLayout(Context context) {
		super(context);
	}

	public ResizeLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//		TTLog.s("onMeasure() ---> width = " + widthMeasureSpec
//				+ " , height = " + heightMeasureSpec);
	}

	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		super.onLayout(changed, l, t, r, b);
//		TTLog.s("onLayout() -----> changed = " + changed + " , l = "
//				+ l + " , t = " + t + " , r = " + r + " , b = " + b);
	}

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {
		super.onSizeChanged(w, h, oldw, oldh);
		if (initHeight < h) {
			initHeight = h;
		}
		TTLog.s("onSizeChanged() ----> w = " + w + " , h = " + h
				+ " , oldW = " + oldw + " , oldH = " + oldh);
		if(listener!=null){
			boolean flag;
			if(initHeight - h > 0){
				flag=true;
			}else{
				flag=false;
			}
			listener.onResize(flag,oldh-h);
		}
	}

	public void setOnRelativeLayoutResizeListener(OnRelativeLayoutResizeListener listener) {
		this.listener = listener;
	}

	public interface OnRelativeLayoutResizeListener {
		void onResize(boolean flag,int space);
	}
}